package com.study.lxy.concurrent.lock;

import java.util.concurrent.locks.Lock;

public class Worker extends Thread {
    private String name;
    private Lock lock;
    Worker(String name,Lock lock){
        this.name = name;
        this.lock = lock;
    }
    @Override
    public void run(){

        lock.lock();
        // MutexLock是不可重入的锁，如果同一线程不先释放锁而再次获取锁，则会阻塞
        //lock.lock();
        try {
            System.out.println("locked by " + name);
            sleep(1000);
        } catch (Exception e){
            System.out.println("xxxxx");
        } finally {
            lock.unlock();
            //System.out.println("unlocked by " + name);
        }
    }
}
